/**
 * Validate 通用验证
 */
export default {
  // 手机号
  mobile: [
    {
      required: true,
      message: '请输入手机号',
      trigger: ['change', 'blur'],
    },
    {
      validator: (rule, value, callback) => {
        return uni.$uv.test.mobile(value)
      },
      message: '手机号码格式不正确',
      trigger: ['change', 'blur'],
    },
  ],
  // 账户
  account: [
    {
      required: true,
      min: 5,
      message: '请输入至少5位的账号',
      trigger: ['change', 'blur'],
    },
  ],

  // 图形验证码
  imgcode: [
    {
      required: true,
      min: 4,
      message: '请输入图形验证码',
      trigger: ['change', 'blur'],
    },
  ],

  // 短信验证码
  smscode: [
    {
      required: true,
      min: 4,
      pattern: /^\d+$/,
      message: '请输入有效的短信验证码',
      trigger: ['change', 'blur'],
    },
  ],

  // 密码
  password: [
    {
      required: true,
      message: '请输入密码',
      trigger: ['change', 'blur'],
    },
    {
      pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,24}$/,
      message: '需同时含有字母和数字，长度在6-24之间',
      trigger: ['change', 'blur'],
    },
  ],

  // 真实姓名
  realName: [
    {
      required: true,
      message: '请输入持卡人姓名',
      trigger: ['change', 'blur'],
    },
    {
      validator: (rule, value, callback) => {
        return uni.$uv.test.chinese(value)
      },
      message: '请输入汉字',
      trigger: ['change', 'blur'],
    },
  ],

  // 开户行
  bankName: [
    {
      required: true,
      message: '请输入开户行',
      trigger: ['change', 'blur'],
    },
    {
      validator: (rule, value, callback) => {
        return uni.$uv.test.chinese(value)
      },
      message: '请输入汉字',
      trigger: ['change', 'blur'],
    },
  ],

  // 银行卡号
  bankCode: [
    {
      required: true,
      message: '请输入银行卡号',
      trigger: ['change', 'blur'],
    },
    {
      validator: (rule, value, callback) => {
        return uni.$uv.test.number(value)
      },
      message: '请输入正确账号',
      trigger: ['change', 'blur'],
    },
  ],

  // 支付宝账号
  alipayAccount: [
    {
      required: true,
      message: '请输入支付账号',
      trigger: ['change', 'blur'],
    },
    {
      validator: (rule, value, callback) => {
        let isRange = uni.$uv.test.rangeLength(value, [6, 30])
        let isAsterisk = uni.$uv.test.contains(value, '*')

        return isRange && !isAsterisk
      },
      message: '请输入正确账号',
      trigger: ['change', 'blur'],
    },
  ],
}
